package evolution.tests;

import java.util.Random;

import junit.framework.Assert;

import org.junit.Test;

import evolution.random.SFMT19937RandomGen;

public class EvolutionTests {

	@Test
	public void testSFMT19937RandomGen() {
		Assert.assertEquals(SFMT19937RandomGen.scale(0, 1),
				SFMT19937RandomGen.scale(0, 500) / 500);
		Assert.assertEquals(SFMT19937RandomGen.scale(400, 1),
				SFMT19937RandomGen.scale(400, 500) / 500);
		Assert.assertEquals(1.0, SFMT19937RandomGen.scale(Integer.MAX_VALUE, 1));
		Assert.assertEquals(0.0, SFMT19937RandomGen.scale(Integer.MIN_VALUE, 1));
	}

	@Test
	public void testRandom() {
		double minRange = -1.2;
		double maxRange = 2.35;
		Random rand = new Random();
		for (int i = 0; i < 1000000000; i++) {
			double retVal = rand.nextDouble()
					* (difference(maxRange, minRange)) + minRange;
			if (retVal > maxRange) {
				Assert.fail();
			}
			if (retVal < minRange) {
				Assert.fail();
			}
			System.out.println(retVal);
		}
	}

	private double difference(double d1, double d2) {
//		if (d2 < 0) {
//			return d1 - ((-1) * d2);
//		} else {
			return d1 - d2;
//		}
	}
}
